<?php
session_start();
include('includes/db/sql.functions.php');
ob_start();
$query=get_all_biobits();
?>

<script type="text/javascript" src="js/validaciones.js"></script>

<script>
var idgen;
idgen=1;
$(document).ready(function(){ 
	
                $( "input:submit, a, button", ".botonMolon" ).button();
                $( "a", ".demo" ).click(function() { return false; });
                $( "#tabs" ).tabs();
                $("#formGen").hide();
       
});
</script>

<?php 

$bb_name = $_GET['bb'];
$tabsN= $_SESSION['addWireForm']['type'];
$num=substr($tabsN,-1);
$errores = $_SESSION['addWireForm'][$tabsN]['errores'];
$values = $_SESSION['addWireForm'][$tabsN]['values'];
${"name".$num} = $values["name"];
${"comments".$num}= $values["comments"];
${"testedBy".$num} = $values["testBy"];
$targInd = $values["targInd"];
$targInd_species=$values["targInd_species"];;
$targInd_fasta=$values["targInd_fasta"];


if(isset($_SESSION['addWireForm'][$tabsN]['errores'])){ 
	if(isset($_SESSION['addWireForm'][$tabsN]['errores']["name"])){
		${"errname".$num} = $errores["name"];
		
	}
	if(isset($_SESSION['addWireForm'][$tabsN]['errores']["comments"])){
		${"errcomments".$num}= $_SESSION['addWireForm'][$tabsN]['errores']["comments"];

	}
	if(isset($_SESSION['addWireForm'][$tabsN]['errores']["testBy"])){
		${"errtestedBy".$num}= $_SESSION['addWireForm'][$tabsN]['errores']["testBy"];

	}
	if(isset($_SESSION['addWireForm'][$tabsN]['errores']["targInd"])){
		$errtargInd= $_SESSION['addWireForm'][$tabsN]['errores']["targInd"];

	}
	if(isset($_SESSION['addWireForm'][$tabsN]['errores']["targInd_species"])){
		$errtargInd_species = $errores["targInd_species"];
		
	}
	if(isset($_SESSION['addWireForm'][$tabsN]['errores']["targInd_fasta"])){
		$errtargInd_fasta = $errores["targInd_fasta"];
		
	}
}else{
	$errname="";
	$errcomments="";
	$errtestedBy="";
	$targInd="";
	$targInd_fasta ="";
	$targInd_species = "";
}

?>

<div id="titlBB">Adding info to: <?php echo $bb_name?></div>
<div id="tabs">
<ul>
	<li><a href="#tabs-1">EHW</a></li>
	<li><a href="#tabs-2">RHW</a></li>
	<li><a href="#tabs-3">SINK</a></li>
</ul>
<div id="tabs-1">
<form onsubmit="return val_ehw()" action="val_wire.php?bb=<?php echo $bb_name;?>" method="post">
<fieldset><!-- EWS --> <legend>Input data</legend>
<div id="div_hws_name"><label id="label_hws_name" for="hws_name">Name:</label>
<input id="hws_name" name="name" class="<?php if($errname1){
	echo "errorForm";
	}?>" type="text"
	value="<?php if(isset($name1)){ echo $name1; }?>" /> 
<?php 
	if($errname1){
		?>
		<span id="span_hws_name"  class="errorForm";><?php echo $errname1;?></span>
        <?php
	}else{
		?>
		<span id="span_hws_name"> Name?</span>
        <?php	
	}
	?>
</div>

<div id="div_hws_comments"><label id="label_hws_comments" for="hws_comments">Comments:</label>
<input id="hws_comments" name="comments"  class="<?php if($errcomments1){
	echo "errorForm";
	} ?>" type="text"
	value="<?php if($comments1){ echo $comments1; }?>" /> 
<?php 
	if($errcomments1){
		?>
		<span id="span_hws_comments"  class="errorForm";><?php echo $errcomments1;?></span>
        <?php
	}else{
		?>
		<span id="span_hws_comments"> Remember the comments</span>
        <?php	
	}
	?></div>

<div id="div_hws_testBy"><label id="label_hws_testBy" for="hws_testBy">Test
by:</label> <input id="hws_testBy" name="testBy"  class="<?php if($errtestedBy1){
	echo "errorForm";
	}?>" type="text"
	value="<?php if(isset($testedBy1)){ echo $testedBy1; }?>" /> 
<?php 
	if($errtestedBy1){
		?>
		<span id="span_hws_testBy"  class="errorForm";><?php echo $errtestedBy1;?></span>
        <?php
	}else{
		?>
		<span id="span_hws_testBy"> Who tested it?</span>
        <?php	
	}
	?></div>
<input type="hidden" name="type" value="tabs-1">
<div class="botonMolon" id="div_submitEHW">
<button class="buttonTab" id="submitEHW">Send</button>
</div>


</fieldset>

</form>
<div id="GenFormEHW"></div>

<button id="EHW" class="addGene">Add new Gene</button>

</div>



<div id="tabs-2">
<form onsubmit="return val_rws()" action="val_wire.php?bb=<?php echo $bb_name;?>" method="post">
<fieldset><!-- RWS --> <legend>Input data</legend>
<div id="div_rws_name"><label id="label_rws_name" for="rws_name">Name:</label>
<input id="rws_name" name="name" class="<?php if($errname2){
	echo "errorForm";
	}?>" type="text"
	value="<?php if(isset($name2)){ echo $name2; }?>" /> 
<?php 
	if($errname2){
		?>
		<span id="span_rws_name"  class="errorForm";><?php echo $errname2;?></span>
        <?php
	}else{
		?>
		<span id="span_rws_name"> Name?</span>
        <?php	
	}
	?>
</div>

<div id="div_rws_comments"><label id="label_rws_comments" for="rws_comments">Comments:</label>
<input id="rws_comments" name="comments"  class="<?php if($errcomments2){
	echo "errorForm";
	} ?>" type="text"
	value="<?php if($comments2){ echo $comments2; }?>" /> 
<?php 
	if($errcomments2){
		?>
		<span id="span_rws_comments"  class="errorForm";><?php echo $errcomments2;?></span>
        <?php
	}else{
		?>
		<span id="span_rws_comments"> Remember the comments</span>
        <?php	
	}
	?></div>

<div id="div_rws_testBy"><label id="label_rws_testBy" for="rws_testBy">Test
by:</label> <input id="rws_testBy" name="testBy"  class="<?php if($errtestedBy2){
	echo "errorForm";
	}?>" type="text"
	value="<?php if(isset($testedBy2)){ echo $testedBy2; }?>" /> 
<?php 
	if($errtestedBy2){
		?>
		<span id="span_rws_testBy"  class="errorForm";><?php echo $errtestedBy2;?></span>
        <?php
	}else{
		?>
		<span id="span_rws_testBy"> Who tested it?</span>
        <?php	
	}
	?></div>
	
<div id="div_targInd"><label id="label_targInd"
	for="targInd">Target Inductor:</label> <input id="targInd"
	name="targInd" type="text"  class=" <?php if($errtargInd){
	echo "errorForm";
	}?>" type="text"
	value="<?php if(isset($targInd)){ echo $targInd; }?>" /> 
<?php 
	if($errtargInd){
		?>
		<span id="span_rws_targInd"  class="errorForm";><?php echo $errtargInd;?></span>
        <?php
	}else{
		?>
		<span id="span_rws_targInd"> Remember the target inductor</span>
        <?php	
	}
	?></div>

<div id="div_targInd_species"><label id="label_targInd_species"
	for="targInd_species">Target Inductor specie:</label> <input id="targInd_species"
	name="targInd_species" type="text"  class=" <?php if($errtargInd_species){
	echo "errorForm";
	}?>" type="text"
	value="<?php if(isset($targInd_species)){ echo $targInd_species; }?>" /> 
<?php 
	if($errtargInd_species){
		?>
		<span id="span_rws_targInd_species"  class="errorForm";><?php echo $errtargInd_species;?></span>
        <?php
	}else{
		?>
		<span id="span_rws_targInd_species"> Remember the target specie</span>
        <?php	
	}
	?></div>
	

<div id="div_targInd_fasta"><label id="label_targInd_fasta"
	for="targInd_fasta">Target Inductor FASTA:</label> <input id="targInd_fasta"
	name="targInd_fasta" type="text"  class=" <?php if($errtargInd_fasta){
	echo "errorForm";
	}?>" type="text"
	value="<?php if(isset($targInd_fasta)){ echo $targInd_fasta; }?>" /> 
<?php 
	if($errtargInd_fasta){
		?>
		<span id="span_rws_targInd_fasta"  class="errorForm";><?php echo $errtargInd_fasta;?></span>
        <?php
	}else{
		?>
		<span id="span_rws_targInd_fasta"> Remember the target inductor FASTA</span>
        <?php	
	}
	?></div>


<input type="hidden" name="type" value="tabs-2">
<div class="botonMolon" id="div_submitrws">
<button class="buttonTab" id="submitrws">Send</button>
</div>


</fieldset>

</form>
<div id="GenFormrws"></div>

<button id="rws" class="addGene">Add new Gene</button>

</div>



<div id="tabs-3">
<form onsubmit="return val_sink()" action="val_wire.php?bb=<?php echo $bb_name;?>" method="post">
<fieldset><legend>Input data</legend>
<div id="div_sink_name"><label id="label_sink_name" for="sink_name">Name:</label>
<input id="sink_name" name="name" type="text" class=" <?php if($errname3){
	echo "errorForm";
	}?>" type="text"
	value="<?php if(isset($name3)){ echo $name3; }?>" /> 
<?php 
	if($errname3){
		?>
		<span id="span_sink_name"  class="errorForm";><?php echo $errname3;?></span>
        <?php
	}else{
		?>
		<span id="span_sink_name"> Name?</span>
        <?php	
	}
	?></div>

<div id="div_commentsS"><label id="label_commentsS" for="bb_commentsS">Comments:</label>
<input id="sink_comments" name="comments" type="text" class=" <?php if($errcomments3){
	echo "errorForm";
	}?>" type="text"
	value="<?php if(isset($comments3)){ echo $comments3; }?>" /> 
<?php 
	if($errcomments3){
		?>
		<span id="span_sink_comments"  class="errorForm";><?php echo $errcomments3;?></span>
        <?php
	}else{
		?>
		<span id="span_sink_comments"> Remember the comments</span>
        <?php	
	}
	?></div>

<div id="div_testByS"><label id="label_testByS" for="bb_testByS">Test
by:</label> <input id="sink_testBy" name="testBy" type="text"
	class=" <?php if($errtestedBy3){
	echo "errorForm";
	}?>" type="text"
	value="<?php if(isset($testedBy3)){ echo $testedBy3; }?>" /> 
<?php 
	if($errtestedBy3){
		?>
		<span id="span_sink_testBy"  class="errorForm";><?php echo $errtestedBy3;?></span>
        <?php
	}else{
		?>
		<span id="span_sink_testBy"> Who tested it?</span>
        <?php	
	}
	?></div>
	
<input type="hidden" name="type" value="tabs-3">
<div class="botonMolon" id="div_submitSINK">
<button class="buttonTab" id="submitSINK">Send</button>
</div>

</fieldset>
</form>
<div id="GenFormSINK"></div>

<button id="SINK" class="addGene">Add new Gene</button>
</div>
</div>




<script>


</script>



<!-- AJAX -->

<script type="text/javascript">
        $("#biobitForm").submit(function(event){
            //event.preventDefault();
            var form = this;
            if(validateForm(form)){
                submitForm(form);
            }
            return false;
        });
    </script>

<script type="text/javascript">  
function validateForm(form){
    //Validar por JS
    var str = form["bbname"].value;
    if(!str || str == ' '){
        $('#error').html("Empty comment text");
        return false;
    }
    return true;
}
        
function submitForm(form){
   var data = $(form).serialize();
   $.post($(form).attr("action"), data, function(data){
         var namebb= form["bbname"].value;
         form["bbname"].value = "Funciona";
        // $('#error').html('Success! '+ $(form).attr("action"));
		if(data==-9){
				$("#titlBB").append("Your are now adding new resources to the Biobit "+namebb);
				$('#biobitForm').hide();
				$('#tabs').show();
			}else {
				$('#biobitForm').hide();
				$.post("forms/biobitForm.php", { biobitid: 0 }, function(data){
					$('#newBiobitForm').html(data);
				});
		}
        });
}

 
  </script>


<script type="text/javascript">

$(".addGene").hide();
	$(".addGene").click(function(){
			  var button=this;
              var id = this.id;
              var name;
              name=id;
              if(id=="EHW"){
					name="hws";
              }
              if(id=="SINK"){
					name="sink";
              }
              
              if(getVal(name+"_name")==""){
					alert("Insert the half wire name first.");
            }else{
              idgen++;
              $.post("forms/genForm.php", {source: 'addWire.php', genid: idgen}, function(data){
            	  $("#GenForm"+id).html(data);
              	 $(button).hide();
              });
            }
              
            
        });
   
    
  
 </script>




<?php
$content= ob_get_contents();
ob_end_clean();
include_once('template.php');

?>